package com.spc.redis.serializer;

/**
 * @author alex
 * @version v1.0 2021/3/18
 */
public final class SerializerUtil {

    /**
     * is primitive or string
     *
     * @param target
     * @return
     */
    public static boolean isPrimitiveOrString(Class<?> target) {
        if (target.isAssignableFrom(String.class)) {
            return true;
        }
        for (Class<?> standardPrimitive : PRIMITIVE_TYPES) {
            if (standardPrimitive.isAssignableFrom(target)) {
                return true;
            }
        }
        return false;
    }

    public static boolean isPrimitiveOrString(Object target) {
        if (target instanceof String) {
            return true;
        }
        Class<?> classOfPrimitive = target.getClass();
        return isPrimitiveOrString(classOfPrimitive);
    }

    private static final Class<?>[] PRIMITIVE_TYPES = {int.class, long.class, short.class,
            float.class, double.class, byte.class, boolean.class, char.class, Integer.class, Long.class,
            Short.class, Float.class, Double.class, Byte.class, Boolean.class, Character.class};
}
